<?php
/**
 * 前端用户模型
 */
class UserModel extends Model {
    public function  __construct() {
        parent::__construct();
    }

    /**
     * 检查用户是否可以登录
     * @param <type> $firstName
     * @param <type> $lastName
     * @param <type> $userId
     * @return <type>
     */
    public function checkUserNameId($firstName,$lastName,$userId) {
        $map['first_name']=$firstName;
        $map['last_name']=$lastName;
        $map['user_id']=$userId;
        if($d=D('User')->where($map)->find()) {
            return $d;
        }
        return false;
    }

    /**
     * 添加一个新用户
     * @param <type> $user_id
     * @param <type> $first_name
     * @param <type> $last_name
     * @param <type> $leader_id 
     */
    public function insertUser($user_id,$first_name,$last_name,$leader_id){
        $data=array(
            'user_id'=>$user_id,
            'first_name'=>$first_name,
            'last_name'=>$last_name,
            'leader_user_id'=>$leader_id
        );
        return $this->add($data);
    }

    /**
     * 获取用户列表
     * @param <type> $page
     * @param <type> $page_size
     * @param <type> $orderby 
     */
    public function getUserList($page_size,$orderby='user_id ASC',$sqlwhere=''){
        import("ORG.Util.Page");
        $count = $this->where("1=1".$sqlwhere)->count();
        $Page = new Page($count,$page_size);
        $show = $Page->show();
        $list = $this->where("1=1".$sqlwhere)->order($orderby)->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($list as &$u){
			$user_id=$u['leader_user_id'];
			$i=$this->getUserInfo($user_id);
			$u['leader_nom']=$i['first_name'];
			$u['leader_Prenom']=$i['last_name'];
		}
        return array($show,$list,$count);
    }

    /**
     * 获取一个用户的详细信息
     * @param <type> $user_id
     */
    public function getUserInfo($user_id){
        return $this->where("user_id=".$user_id)->find();
    }






}

?>